import {queryFileHomePage,} from '@/services/workspace';
import {saveFileCodeToName} from '@/utils/bwdautil';

export default {
  namespace: 'homeFileModel',

  state: {
    // 列表数据
    data: {
      dataList: [
        {code: 'private_file', name: '个人文件'},
        {code: 'share_file', name: '共享文件'},
        {code: 'group_file', name: '自定义组文件'},
        {code: 'out_side_file', name: '外接文件'},
      ],
      pageNum: 0,
      pageSize: 10,
      totalCount: 4,
    },
    //目录树结构
    dirTreeList: [],

  },

  effects: {
    * queryFileHomePage({payload}, {call, put}) {
      const response = yield call(queryFileHomePage, payload);
      if (response && response.result == 'ok') {
        yield put({
          type: 'saveFileHomePage',
          payload: response,
        });

        if (response.data && response.data.dataList && response.data.dataList.size() > 0) {
          saveFileCodeToName(response.data.dataList);
        }


      }
    },


  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    saveFileHomePage(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
